/* this module implements a generic FIFO queue. It is mainly used by the I/O devices. */

#ifndef PCB_FIFO_QUEUE_H
#define PCB_FIFO_QUEUE_H

#include "types.h"
#include "error_codes.h"
#include "linked_list.h"

#define MAX_QUEUE_LENGTH NUMBER_MAX_PROCESSES

/* type declaration */

typedef struct _fifo_queue {
  list head; //points to the head of the queue
  list tail; //points to the tail of the queue
}fifo_queue;


/* function declarations */

/* resets the queue fifo */
void fifo_queue_reset(fifo_queue* fifo);

/* puts new at the end of the queue. Returns 1 if success or 0 if the queue is full */
int32_t fifo_queue_put(fifo_queue* fifo, void* new);

/* returns the head of the queue and removes it. Returns NULL if the queue is empty */
void* fifo_queue_get(fifo_queue* fifo);

/* removes target from the queue fifo. Uses the function compare to know whether the correct element has been found. compare must take two pointers as arguments and returns a boolean result. It also uses the function free_data to know how to free a link's payload. free_data takes one pointer as parameter and returns a boolean result, indicating if the free worked or not. Returns SUCCESS in case of success, FAILURE otherwise. */
int32_t fifo_queue_remove(fifo_queue* fifo, void* target, int32_t (*compare)(void*, void*), int32_t (*free_data)(void*));

#endif
